﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;
using System.Web.Security;
using System.Configuration;

namespace eStreamChat
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public override String StyleSheetTheme
        {
            get { return "Paper"; }
        }
        protected void LoginUser_OnLoggedIn(object sender, EventArgs e)
        {
            string id = "";
        //    if (User.Identity.IsAuthenticated)
        //    {

                id = User.Identity.Name;
                //id = Membership.GetUser().UserName;
                MembershipUser user = Membership.GetUser(LoginUser.UserName);
                id = user.UserName;
                string secretKey = "abc123";


                string timestamp = DateTime.Now.ToString("yyMMddhhmmss");
                SHA1Managed sha1 = new SHA1Managed();
                byte[] paramBytes = Encoding.UTF8.GetBytes(id + timestamp + secretKey);
                byte[] hashBytes = sha1.ComputeHash(paramBytes);
                string hash = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();

                Response.Redirect(
                    //string.Format("http://localhost:63416/" + "ChatRoom.aspx?id={0}&timestamp={1}&hash={2}",
                    //id, timestamp, hash));
                  string.Format(ConfigurationSettings.AppSettings["RemoteAuthUrl"] + "ChatRoom.aspx?id={0}&timestamp={1}&hash={2}", id, timestamp, hash));
        //    }
        //    else
        //        Response.Redirect(
        //          string.Format(ConfigurationSettings.AppSettings["RemoteAuthUrl"]+"Login.aspx" ));
            
        }

    }
}